/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enterprise.jsf_jpa_war;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Named;

@Named
public class Localizacion{ // implements Serializable {
    
    private String idioma;

    public void setIdioma(String idioma) {
        this.idioma = idioma;
    }
    private String SImg_en,SImg_es,SImg_de,SImg_fr;

    public String getSImg_en() {
        return SImg_en;
    }

    public String getSImg_es() {
        return SImg_es;
    }

    public String getSImg_de() {
        return SImg_de;
    }

    public String getSImg_fr() {
        return SImg_fr;
    }

    public String getIdioma() {
        return idioma;
    }
    
    /*
    public String CLocaleEN(){
        idioma = "en";
        FacesContext.getCurrentInstance()
            .getViewRoot().setLocale(new Locale(idioma));   
        return "app-main";
   }
    public String CLocaleES(){
        idioma = "es";
        FacesContext.getCurrentInstance()
            .getViewRoot().setLocale(new Locale(idioma));    
        return "app-main";
   }
   */
    public String CLocaleXX(ActionEvent event){
        idioma = getActionAttribute(event, "idiomaXX");
        FacesContext.getCurrentInstance()
            .getViewRoot().setLocale(new Locale(idioma));    
        
        //determina el estilo de cada la imagen para cada idioma
        SImg_en = "";
        SImg_es = "";
        SImg_de = "";
        SImg_fr = "";
        if(idioma.equals("en")){ SImg_en = "border-style: solid;border-width: 2px;"; }
        if(idioma.equals("es")){ SImg_es = "border-style: solid;border-width: 2px;"; }
        if(idioma.equals("de")){ SImg_de = "border-style: solid;border-width: 2px;"; }
        if(idioma.equals("fr")){ SImg_fr = "border-style: solid;border-width: 2px;"; }
        
        
        return "app-main";
   }
    
    
    public static String getActionAttribute(ActionEvent event, String name) {
        return (String) event.getComponent().getAttributes().get(name);
    }

}
